#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
#include <cstring>
#include <vector>
#include<queue>
using namespace std;
#define ll long long 
#define MAXL 200005
#define mod 998244353
int a[MAXL * 4 + 5];
int main()
{
	int n1, n2;
	char a[MAXL];
	char b[MAXL];
	cin >> n1 >> n2;
	for (int i = 0; i < n1; i++)
	{
		cin >> a[i];
	}
	for (int i = 0; i < n2; i++)
	{
		cin >> b[i];
	}
	if (a[0] != b[0] || a[n1] != b[n2])
	{
		cout << "No" << endl;
	}
	else {
		for(int )
	}
}